package com.ruoyi.yuyuan.Controller;

import com.ruoyi.yuyuan.DTO.BlogPracticeDTO;
import com.ruoyi.yuyuan.DTO.Result;
import com.ruoyi.yuyuan.Service.IPracticeBlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @Author: kestrel
 * @Version:1.0
 * @Date: 2024/5/29
 */
@RestController
@RequestMapping("/practiceBlog")
public class PracticeBlogController {
    @Autowired
    private IPracticeBlogService practiceBlogService;

    //发布陪教贴
    @PostMapping("/publish")
    public Result publishPractice(@RequestBody BlogPracticeDTO blogPracticeDTO) throws InterruptedException {
        return practiceBlogService.publishPractice(blogPracticeDTO);
    }

    //更新陪教贴
    @PostMapping("/update/{blogId}")
    public Result updatePractice(@RequestBody BlogPracticeDTO blogPracticeDTO,@PathVariable Long blogId) throws InterruptedException {
        return practiceBlogService.updatePractice(blogPracticeDTO,blogId);
    }

    //获取陪教贴
    @GetMapping("/{blogId}")
    public Result getSinglePractice(@PathVariable Long blogId){
        return practiceBlogService.getSinglePractice(blogId);
    }

    //分页查询陪教贴
    @GetMapping("/page/{startId}")
    public Result getPractices(@PathVariable Long startId){
        return practiceBlogService.getPractices(startId);
    }


    //搜索陪练帖子
    @GetMapping("/SearchPractices/{searchKeyWord}/{type}")
    public Result getSearchPractices(@PathVariable String searchKeyWord, @PathVariable Short type) throws IOException {
        return practiceBlogService.getSearchPractices(searchKeyWord, type);
    }
}
